<template>
  <div class="searchCurrency">
    <x-header :left-options="{backText: ''}"></x-header>
    <div class="searchText">
      <div class="searchIcon">
        <x-icon type="ios-search" size="25"></x-icon>
      </div>
      <input type="text" placeholder="搜索币种" v-model="searchText">
      <img src="../../assets/delate.png" alt="" width="15" height="15" class="delateIcon" @click="searchText=''">
    </div>
    <div class="searchHot">
      <div style="color:#666;margin-left:15px;font-size: 15px;">
        热门搜索
      </div>
      <div class="searchRes">
        <span @click="searchCurr('BTC')">BTC</span>
        <span @click="searchCurr('ETH')">ETH</span>
        <span @click="searchCurr('ADA')">ADA</span>
        <span @click="searchCurr('EOS')">EOS</span>
        <span @click="searchCurr('LTC')">LTC</span>
        <span @click="searchCurr('NEO')">NEO</span>
        <span @click="searchCurr('VEN')">VEN</span>
        <span @click="searchCurr('ETC')">ETC</span>
        <span @click="searchCurr('OKB')">OKB</span>
        <span @click="searchCurr('REP')">REP</span>
      </div>
    </div>
    <div class="addCurrencyType">
      <ul>
        <li v-for="curr in currList">
          <span>{{curr.key}}</span>
          <div class="spanSty">
            <span @click="addCurrency(curr.key)">添加</span>
          </div>
        </li>
      </ul>
    </div>
  </div>
</template>
<script>
  import { XHeader, Radio, Group } from 'vux'
  import http from '../../service/http.js'
  import tips from '../../service/tips.js'
  export default {
    data() {
      return {
        searchText: "",
        currList: []
      }
    },
    watch: {
      searchText(oldText, newText) {
        http.get("/coins/coin?key="+oldText).then((res) => {
          if(res.status==200){
             this.currList=res.data.body;
          }
        })
      }
    },
    methods: {
      searchCurr(text) {
        this.searchText = text;
        http.get("/coins/coin?key="+text).then((res) => {
          debugger;
        })
      },
      addCurrency(name) {
        http.put("/coins/coin", {
          name: name
        }).then((res) => {
          if (res.status == 200) {
            tips.tips(res.data.msg);
          }
        }).catch((res) => {
          tips.tisp(res.msg)
        })
      }

    },
    components: {
      XHeader,
      Group,
      Radio
    }
  }
</script>
<style lang="less">
  body {
    background: #f6f6f6;
  }

  .searchCurrency .vux-header {
    background: #fff;
  }

  .searchCurrency .vux-header .vux-header-title {
    line-height: 40px;
    text-align: center;
    font-size: 18px;
    font-weight: 400;
    color: #000;
  }

  .searchCurrency .vux-header .vux-header-left .left-arrow:before {
    content: "";
    position: absolute;
    width: 12px;
    height: 12px;
    border: 1px solid #000;
    border-width: 1px 0 0 1px;
    -webkit-transform: rotate(315deg);
    transform: rotate(315deg);
    top: 8px;
    left: 7px;
  }

  .searchCurrency .searchHot {
    background: #fff;
    padding-top: 8px;
    border-top: 1px solid #f6f6f6;
  }

  .searchRes {
    padding-left: 6px;
    margin-top: 12px;
  }

  .searchRes span {
    width: 60px;
    height: 25px;
    text-align: center;
    line-height: 25px;
    display: inline-block;
    border: 1px solid #f6f6f6;
    border-radius: 5px;
    background: #f6f6f6;
    margin-bottom: 12px;
    margin-right: 8px;
    color: #666;
    font-size: 13px;
  }

  .delateIcon {
    position: absolute;
    right: 15px;
    top: 7px;
  }

  .searchCurrency .searchText {
    width: 75%;
    height: 30px;
    border: 1px solid #f6f6f6;
    border-radius: 25px;
    position: absolute;
    top: 8px;
    left: 50px;
    background: #f6f6f6;
    overflow: hidden;
    .searchIcon {
      position: absolute;
      left: 10px;
      top: 5px;
    }
    input {
      border: none;
      border-style: none;
      outline: none;
      background: #f6f6f6;
      margin-left: 40px;
      width: 70%;
      margin-top: 8px;
    }
  }

  .searchCurrency .weui-cells_radio .weui-check:checked+.weui-icon-checked:before {
    display: block;
    content: '\EA08';
    color: #FF9960;
    font-size: 16px;
  }

  .addCurrencyType {
    border-top: 1px solid #f6f6f6;
  }

  .addCurrencyType li {
    height: 55px;
    color: #333;
    line-height: 55px;
    background: #fff;
    border-bottom: 1px solid #f6f6f6;
    padding-left: 15px;
    position: relative;
  }

  .spanSty {
    position: absolute;
    right: 15px;
    color: #fea620;
    top: 0px;
    span {
      width: 80px;
      height: 20px;
      border: 1px solid #fea620;
      padding: 1px 13px;
      border-radius: 5px;
      font-size: 13px;
    }
  }
</style>